package com.my.concurrency.threadpool;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author: marshal
 * @date: 2023-04-11 15:15
 */
public class ThreadPoolTest {
    public static void main(String[] args) throws Exception{
        // 创建带有5个非核心线程的线程池，存活时间为0
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, 5, 0, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), new CustomThreadFactory("thread-pool-test"));
        for (int i =0; i < 5; i++) {
            threadPoolExecutor.submit(() -> {
                System.out.println(Thread.currentThread().getName());
            });
        }

    }
}
